<template>
  <div class="orders-wrapper">
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/about' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片内容 -->
    <el-card>
      <!-- 头部内容 -->
      <header>
        <el-input v-model="keyword" placeholder="请输入内容"></el-input>
        <el-button icon="el-icon-search" @click="search"></el-button>
      </header>

      <!-- 表格主要内容 -->
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status != 0"
              >已付款</el-tag
            >
            <el-tag type="danger" v-if="scope.row.pay_status == 0"
              >未付款</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">
            <div>
              {{ scope.row.create_time | timeForment }}
            </div>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120px">
          <template slot-scope="scope">
            <el-button
              @click="showEdit(scope.row)"
              type="primary"
              icon="el-icon-edit"
              size="small"
            ></el-button>
            <el-button
              @click="showProgress(scope.row)"
              type="success"
              icon="el-icon-location"
              size="small"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[2, 5, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>

    <!-- 点击修改弹出对话框 -->
    <el-dialog title="修改地址" :visible.sync="editDialogFormVisible">
      <el-form :model="editForm" :rules="editrules" ref="editForm">
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="editForm.address2"
            :options="cityList"
            :props="{
              expandTrigger: 'hover',
              label: 'label',
              value: 'value',
              children: 'children',
            }"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>

        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="editForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="doEdit">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 点击弹出进度对话框 -->
    <el-dialog title="查看物流进度" :visible.sync="progressDialogFormVisible">
      <el-timeline>
        <el-timeline-item
          v-for="(item, index) in myData.data"
          :key="index"
          :timestamp="item.time"
        >
          {{ item.context }}
        </el-timeline-item>
      </el-timeline>

      <div slot="footer" class="dialog-footer">
        <el-button @click="progressDialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="progressDialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import cityList from "@/assets/citydata";
import myData from "@/assets/myData";
export default {
  name: "orders",
  data() {
    return {
      // 渲染相关
      tableData: [],
      keyword:"",
      queryInfo: {
        query: this.keyword,
        pagenum: 1,
        pagesize: 5,
      },
      total: 0,
      //   编辑相关
      editDialogFormVisible: false,
      cityList,
      myData,
      editForm: {
        address1: "",
        address2: "",
      },
      editrules: {
        address1: [
          { required: true, message: "请输入省市县", trigger: "blur" },
        ],
        address2: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
      },
      //   物流进度相关
      progressDialogFormVisible: false
    };
  },
  created() {
    this.getOrders();
  },
  methods: {
    // 渲染订单列表
    async getOrders() {
      let { data: res } = await this.$axios({
        url: "/api/private/v1/orders",
        method: "GET",
        params: this.queryInfo,
      }).catch((err) => err);
      //   console.log(res);
      if (res.meta.status !== 200) return this.$message.error("渲染列表失败");
      this.tableData = res.data.goods;
      this.total = res.data.total;
    },
    // 搜索
    search() {
      this.queryInfo.pagenum = 1;
      this.getOrders();
    },
    // 选择地址
    handleChange() {},
    // 显示修改框
    showEdit(row) {
      console.log(row, "row");
      this.editDialogFormVisible = true;
    },
    // 执行修改
    doEdit(row) {
      console.log(row);
    },
    // 显示物流进度对话框
    showProgress() {
        this.progressDialogFormVisible = true
    },
    // 分页
    handleSizeChange(val) {
      this.queryInfo.pagesize = val;
      this.getOrders();
    },
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val;
      this.getOrders();
    },
  },
};
</script>

<style lang="scss" scoped>
.orders-wrapper {
  .el-card {
    margin-top: 20px;
    header {
      .el-input {
        width: 20%;
      }
      .el-button {
        margin-left: -1px;
        background: #f5f7fa;
      }
    }
    .el-table {
      margin-top: 20px;
    }
  }
  .el-dialog {
    .el-input {
      width: 89%;
    }
  }
}
</style>